﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DARE
{
    public class CGeneralConfig
    {

    #region fields

        private CDare m_dare;
        private string m_windowTitle;
        private string m_rootDirectory;
        private string m_musicDirectory;
        private string m_soundDirectory;
        private string m_modelDirectory;
        private string m_particleDirectory;
        private bool m_showDebugConsole;
        private bool m_showMouseCursor;
        private System.Globalization.NumberFormatInfo m_numberFormatInfo;

    #endregion

    #region properties

        public CDare Dare
        {
            get { return m_dare; }
        }
#if !WINDOWS_PHONE
        /// <summary>
        /// The general config add the root directory to all paths
        /// </summary>
        public string MusicDirectory
        {
            get { return CDare.Instance.AudioMgr.MusicMgr.MusicDirectory; }
            set { m_musicDirectory = CDare.Instance.AudioMgr.MusicMgr.MusicDirectory = m_rootDirectory + "/" + value; }
        }
#endif
        /// <summary>
        /// This is the absolute music path builded with the root directory and the music directory.
        /// Form is like: "Content/Music/", for RootDirectory = "Content" and MusicDirectory = "Music".
        /// If nothing is set an empty string will be returned.
        /// </summary>
        public string AbsoluteMusicPath
        {
            get
            {
                string path = "";

                if (m_rootDirectory != null && m_rootDirectory != "")
                    path += m_rootDirectory + "/";
                if (m_musicDirectory != null && m_musicDirectory != "")
                    path += m_musicDirectory + "/";
                return path;
            }
        }
#if !WINDOWS_PHONE
        public string SoundDirectory
        {
            get { return CDare.Instance.AudioMgr.SoundMgr.SoundDirectory; }
            set { m_soundDirectory = CDare.Instance.AudioMgr.SoundMgr.SoundDirectory = m_rootDirectory + "/" + value; }
        }
#endif
        public string AbsoluteSoundPath
        {
            get
            {
                string path = "";

                if (m_rootDirectory != null && m_rootDirectory != "")
                    path += m_rootDirectory + "/";
                if (m_soundDirectory != null && m_soundDirectory != "")
                    path += m_soundDirectory + "/";
                return path;
            }
        }

        public string ModelDirectory
        {
            get { return m_modelDirectory; }
            set { m_modelDirectory = value; }
        }

        public string AbsoluteModelPath
        {
            get
            {
                string path = "";

                if (m_rootDirectory != null && m_rootDirectory != "")
                    path += m_rootDirectory + "/";
                if (m_modelDirectory != null && m_modelDirectory != "")
                    path += m_modelDirectory + "/";
                return path;
            }
        }

        public string ParticleDirectory
        {
            get { return m_particleDirectory; }
            set { m_particleDirectory = value; }
        }

        public string AbsoluteParticlePath
        {
            get
            {
                string path = "";

                if (m_rootDirectory != null && m_rootDirectory != "")
                    path += m_rootDirectory + "/";
                if (m_particleDirectory != null && m_particleDirectory != "")
                    path += m_particleDirectory + "/";
                return path;
            }
        }

        public string WindowTitle
        {
            get { return m_windowTitle; }
            set { m_windowTitle = m_dare.Game.Window.Title = value; }
        }

        public string RootDirectory
        {
            get { return m_rootDirectory; }
            set 
            { 
                //m_dare.Game.Content.Dispose();
                //m_dare.Game.Content = new Microsoft.Xna.Framework.Content.ContentManager(
                m_rootDirectory = m_dare.Game.Content.RootDirectory = value;
            }
        }

        public bool ShowDebugConsole
        {
            get { return m_showDebugConsole; }
            set             
            { 
                if (m_dare.DebugMgr != null)
                    m_showDebugConsole = m_dare.DebugMgr.DebugConsoleEnabled = value;
                else
                    m_showDebugConsole = value;
            }
        }

        public bool ShowMouseCursor
        {
            get { return m_showMouseCursor; }
            set { m_showMouseCursor = m_dare.Game.IsMouseVisible = value; }
        }

        public System.Globalization.NumberFormatInfo NumberFormatInfo
        {
            get { return m_numberFormatInfo; }
        }

    #endregion

    #region ctor

        public CGeneralConfig(CDare dare)
        {
            Initialize(dare);
        }

        private void Initialize(CDare dare)
        {
            m_dare = dare;
            WindowTitle = "";
            // cannot be set 2 times, need internet to check how to create a ContentManager again :P
            RootDirectory = "Content";
            m_musicDirectory = null;
            m_soundDirectory = null;
            m_modelDirectory = null;
            m_particleDirectory = null;
            ShowDebugConsole = false;
            ShowMouseCursor = false;
            m_numberFormatInfo = System.Globalization.NumberFormatInfo.CurrentInfo.Clone() as System.Globalization.NumberFormatInfo;
            m_numberFormatInfo.NumberDecimalSeparator = ".";
        }

    #endregion

    }
}
